<template>
  <div class="AD-box">
    <!--  v-for="(item,index) in AD" :key="index" :class="[ index % 2 == 0 ? 'actevr' : '']" -->
    <div
      class="AD"
      v-for="(item, index) in AD"
      :key="index"
      :class="[index % 2 == 0 ? 'actevr' : '']"
    >
      <div class="AD-text-one" @click="TransmitData(item.id , item.al.picUrl , item.name)">
        {{ index + 1 }}
      </div>
      <div class="AD-text-two">
        <van-icon name="like-o" @click="TransmitDataOne(item.id)" />
      </div>
      <div class="AD-text-three" @click="TransmitData(item.id , item.al.picUrl , item.name)">
        {{ item.name }}
      </div>
      <div class="AD-text-four" @click="SingerDetailsPage(item.ar[0].id)">
        {{ item.ar[0].name }}
      </div>
      <div class="AD-text-fver" @click="AlbumDetails(item.al.id)">
        {{ item.al.name }}
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  name: "AD",
  props: {
    AD: {
      default() {
        return {};
      },
    },
  },
  methods: {
    TransmitData(e , i ,l) {
      let shuzu = JSON.parse(JSON.stringify(this.$store.state.play));
      this.$store.commit("updateTwo", { data: e });
      this.axios({
        method: "get",
        url: "/song/url?id=" + e,
      })
        .then((result) => {
          // console.log("result==>", result.data.data[0].url);
          this.$store.commit("updateOne", { data: result.data.data[0].url });
          this.$store.commit("updateL", { data: l });
          this.$store.commit("updateI", { data: i });
        })
        .catch((err) => {
          console.log("err==>", err);
        });
      if (shuzu.length == 0) {
        this.$store.state.play.unshift(e);
      }
      // console.log(shuzu);
      if (shuzu.length > 0) {
        for (let index = 0; index < shuzu.length; index++) {
          // console.log("e==>", e);
          if (e == shuzu[index]) {
            // console.log("shuzu[index]==>", shuzu[index]);
            shuzu.splice(index, 1);
            shuzu.unshift(e);
            this.$store.state.play = shuzu;
            return;
          }
        }
        this.$store.state.play.unshift(e);
      }
      this.axios({
        method: "get",
        url: "/song/detail?ids=" + e,
      })
        .then((result) => {
          // console.log("result==>", result.data.songs);
          // this.like = result.data.songs;
          this.$store.commit("update", { data: result.data.songs[0] });
        })
        .catch((err) => {
          console.log("err==>", err);
        });
      this.axios({
        method: "get",
        url: "/lyric?id=" + e,
      })
        .then((result) => {
          // console.log("result==>", result.data.lrc.lyric);
          this.$store.commit("updateLyric", { data: result.data.lrc.lyric });
        })
        .catch((err) => {
          console.log("err==>", err);
        });
    },
    TransmitDataOne(e) {
      let shuzu = JSON.parse(JSON.stringify(this.$store.state.like));
      if (shuzu.length == 0) {
        this.$store.state.like.unshift(e);
        Toast("添加成功！！！");
      }
      // console.log(shuzu);
      if (shuzu.length > 0) {
        for (let index = 0; index < shuzu.length; index++) {
          // console.log("e==>", e);
          if (e == shuzu[index]) {
            // console.log("shuzu[index]==>", shuzu[index]);
            shuzu.splice(index, 1);
            this.$store.state.like = shuzu;
            Toast("取消成功！！！");
            return;
          }
        }
        this.$store.state.like.unshift(e);
        Toast("添加成功！！！");
      }
    },
    SingerDetailsPage(id) {
      // console.log('id==>',id);
      this.$router.push({ name: "SingerDetailsPage", params: { id } });
    },
    AlbumDetails(id) {
      // console.log('id==>',id);
      // this.$router.push({ name: "AlbumDetails", params: { id } });
    },
  },
  created() {},
};
</script>

<style lang="less" scoped>
.actevr {
  background-color: rgb(235, 235, 235);
}
.AD:hover {
  background-color: rgb(230, 230, 230);
}
.AD {
  width: 100%;
  height: 25px;
  font-size: 10px;
  color: rgb(112, 112, 112);
  cursor: pointer;
  .AD-text-one {
    float: left;
    width: 8%;
    height: 25px;
    line-height: 25px;
    text-align: center;
  }
  .AD-text-two {
    float: left;
    width: 7%;
    height: 25px;
    line-height: 25px;
  }
  .AD-text-three {
    float: left;
    width: calc(45% - 10px);
    padding-right: 10px;
    height: 25px;
    line-height: 25px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .AD-text-four {
    float: left;
    width: calc(20% - 10px);
    padding-right: 10px;
    height: 25px;
    line-height: 25px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .AD-text-four:hover {
    color: rgb(29, 29, 29);
  }
  .AD-text-fver:hover {
    color: rgb(29, 29, 29);
  }
  .AD-text-fver {
    float: left;
    width: calc(20% - 10px);
    padding-right: 10px;
    height: 25px;
    line-height: 25px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
</style>